#include <iostream>
#include <string>
using std::cout;
using std::endl;
using std::string;
const float PI = 3.14;

//案例1：图形类的设计
class Figure{
public:
    virtual string getName() = 0;
    virtual float getPerimeter() = 0;
    virtual float getArea() = 0;
};

//定义一个打印图形的函数功能
//统一的一个标准、规范
void print(Figure * pf){
    cout << pf->getName() << "的面积为:" << pf->getArea() << ",周长为:" 
        << pf->getPerimeter() << endl;
}
class Circle : public Figure{
public:
    Circle(float radius)
    :_radius(radius)
    {

    }
    string getName() override{
        return "圆形";
    }
    float getPerimeter() override{
        return 2 * PI * _radius;
    }
    float getArea() override{
        return PI * _radius * _radius;
    }
private:
    float _radius;
};
class Rectangle : public Figure{
public:
    Rectangle(float length, float width)
    :_length(length)
    ,_width(width)
    {

    }
    virtual string getName(){
        return "矩形";
    };
    virtual float getPerimeter(){
        return 2 * _length + 2 * _width;
    };
    virtual float getArea(){
        return _length * _width;
    };

private:
    float _width;
    float _length;
};


void test(){
    //Figure f;error因为它是一个抽象类，所以不可以实例化对象
    Circle cir(3);
    Rectangle rec(1, 2);
    print(&cir);
    print(&rec);
}

int main()
{
    test();
    return 0;
}

